function getMenu(tree) {

	Ext.Ajax.request({
				url : 'orgChartTree!orgChartTree.action',
				method : "post",
				success : function(response, options) {
					var responseTextVale = Ext.util.JSON
							.decode(response.responseText);
					tree.getRootNode().appendChild(Ext.util.JSON
							.decode(responseTextVale));
				}
			});

}

Ext.lib.Ajax.defaultPostHeader += '; charset=utf-8';
Ext.QuickTips.init();

var root = new Ext.tree.AsyncTreeNode({
			expanded : true
		});

var tree = new Ext.tree.TreePanel({
			loader : new Ext.tree.TreeLoader(),
			id : 'orgTree',

			rootVisible : false,
			region : 'west',
			split : true,
			border : true,
			collapsible : false,
			width : 160,
			minSize : 80,
			maxSize : 200,
			animate : true,
			autoScroll : true,
			enableDD : true,
			containerScroll : true

		});

getMenu(tree);

tree.setRootNode(root);

tree.on("click", function(node) {

			flow_orgid.setValue(node.id);
			accountstore.on('beforeload', function() {
									accountstore.baseParams = {
												'filter.flow_orgid' : Ext
														.getCmp('flow_orgid')
														.getValue(),
												'filter.accountName' :''
									}
								});
						accountstore.reload();
		});










// 使用前请修改store & column 对应字段
var flow_orgid = new Ext.form.Hidden({
			name : 'flowUser.flow_orgid',
			id : 'flow_orgid',
			allowBlank : false,
			triggerAction : 'all'
		});
Ext.onReady(function() {
	// 查询帐号start------------------------------------------------
	accountstore = new Ext.data.Store({
				url : 'workflowAccountAction.action?actionType=0',
				reader : new Ext.data.JsonReader({
							root : 'result.result',
							id : 'flow_userid',
							totalProperty : 'result.totalCount'
						}, [{
									name : 'flow_usercode',
									mapping : 'flow_usercode'
								}, {
									name : 'flow_userid',
									mapping : 'flow_userid'
								}, {
									name : 'flow_username',
									mapping : 'flow_username'
								}, {
									name : 'flow_useremail',
									mapping : 'flow_useremail'
								}, {
									name : 'flow_orgid',
									mapping : 'flow_orgid'
								}, {
									name : 'flow_usermobile',
									mapping : 'flow_usermobile'
								}, {
									name : 'flow_orgName',
									mapping : 'flow_orgName'
								}])
			});
			accountstore.baseParams = {
												'filter.flow_orgid' : '',
												'filter.accountName' :''
									}
	accountstore.load();
	var accountsm = new Ext.grid.CheckboxSelectionModel();
	var accountcm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),
			accountsm, {
				header : ' ',
				width : 90,
				hidden : true,
				dataIndex : 'flow_userid'
			}, {
				header : '所属组织',
				width : 90,
				dataIndex : 'flow_orgName'
			}, {
				header : '帐号',
				width : 90,
				dataIndex : 'flow_usercode'
			}, {
				header : '显示名',
				dataIndex : 'flow_username'
			}, {
				header : '电子邮件',
				dataIndex : 'flow_useremail'
			}]);

	var accountGrid = new Ext.grid.GridPanel({
		title : '账号管理',
		region : 'center',
		trackMouseOver : true,
		stripeRows : true,
		autoScroll : true,
		hideCollapseTool : true,
		bufferResize : true,
		loadMask : true,
		
		height : document.body.clientHeight,
		id : 'accountGrid',
		tbar : ['帐号名称', {
					xtype : 'textfield',
					id : 'flow_name'
				}, {
					xtype : "tbseparator"
				}, {
					xtype : 'button',
					text : '查询',
					handler : function() {
						accountstore.on('beforeload', function() {
									accountstore.baseParams = {
										'filter.accountName' : Ext
												.getCmp('flow_name').getValue(),
												'filter.flow_orgid' : Ext
														.getCmp('flow_orgid')
														.getValue()
									}
								});
						accountstore.reload();
					}
				}, {
					xtype : "tbseparator"
				}, {
					xtype : "tbbutton",
					text : "新增帐号",
					handler : function() {
						accountWin.show();
					}
				}, {
					xtype : "tbseparator"
				}, {
					xtype : "tbbutton",
					text : "删除帐号",
					handler : function() {
						var length = accountGrid.getSelectionModel()
								.getSelections().length;
						if (length > 0) {
							Ext.MessageBox.show({
								title : '删除提示',
								msg : '数据即将被删除',
								buttons : Ext.MessageBox.OKCANCEL,
								fn : function(button) {
									if (button == "ok") {
										var rs = accountGrid
												.getSelectionModel()
												.getSelections();
										var deleteAccounts = [];
										for (var i = 0; i < length; i++) {
											deleteAccounts
													.push(rs[i].data.flow_userid);
											accountstore.remove(accountstore
													.getById(rs[i].id));
										};
										Ext.Ajax.request({
											url : 'workflowAccountAction.action?actionType=2',
											success : function() {
												accountstore.reload();
												Ext.Msg.alert("提示", '删除成功');
											},
											failure : function() {
												accountstore.reload();
												Ext.Msg.alert("提示", '数据处理失败');
											},
											params : {
												'filter.ids' : deleteAccounts
														.join(',')
											}
										});
									}
									if (button == "cancel") {
										return;
									}
								}
							});

						} else {
							Ext.Msg.alert("提示", '请选择要删除的数据');
						}
					}
				}

		],
		bbar : new Ext.PagingToolbar({
					pageSize : pageSize,
					store : accountstore,
					displayInfo : true,
					dispalyMsg : '显示第{0}条到{1}条记录，一共{2}条',
					emptyMsg : '没有记录'
				}),
		sm : accountsm,
		cm : accountcm,
		store : accountstore,
		loadMask : true,
		loadMask : {
			msg : '正在加载数据...'
		}
	});
	// 查询帐号end------------------------------------------------

	// 增加帐号start------------------------------------------------
	// 组织store
	orgstore = new Ext.data.Store({
				url : 'workflowAccountAction.action?actionType=-1',
				reader : new Ext.data.JsonReader({
							root : 'orgComb',
							id : 'returnValue',
							totalProperty : ''
						}, [{
									name : 'flow_orgid',
									mapping : 'returnValue'
								}, {
									name : 'flow_orgname',
									mapping : 'displayText'
								}])
			});
	var newaccountForm = new Ext.form.FormPanel({
				// labelAlign: 'top',
				frame : true,
				region : 'north',
				id : 'newaccountForm',
				height : 200,
				bodyStyle : 'padding:5px 5px 0',
				// url : 'Tax!saveTax.action',
				items : [flow_orgid, {
							layout : 'column',

							items : [{
										columnWidth : 1,
										layout : 'form',
										buttonAlign : 'left',
										items : [{
													xtype : 'textfield',
													fieldLabel : '手机号码',
													name : 'flowUser.flow_usermobile',
													id : 'flow_usermobile',
													anchor : '80%',
													allowBlank : false,
													emptyText : ''
												}, {
													xtype : 'textfield',
													fieldLabel : '帐号',
													name : 'flowUser.flow_usercode',
													id : 'flow_usercode',
													anchor : '80%',
													allowBlank : false,
													blankText : '帐号不能为空',
													emptyText : ''
												}, {
													xtype : 'textfield',
													fieldLabel : '显示名',
													name : 'flowUser.flow_username',
													id : 'flow_username',
													anchor : '80%',
													allowBlank : false,
													blankText : '显示名不能为空',
													emptyText : ''
												}, {
													xtype : 'textfield',
													fieldLabel : '密码',
													name : 'flowUser.flow_password',
													id : 'flow_password',
													name : 'flowUser.flow_password',
													anchor : '80%',
													allowBlank : false,
													emptyText : ''
												}, {
													xtype : 'textfield',
													fieldLabel : '电子邮件',
													name : 'flowUser.flow_useremail',
													id : 'flow_usermail',
													anchor : '80%',
													allowBlank : false,
													blankText : '电子邮件不能为空',
													emptyText : '',
													vtype:'email'
												}]
									}]
						}]
			});
	// 增加帐号end------------------------------------------------
	var accountWin = new Ext.Window({
				closeAction : 'hide',
				closable : true,
				draggable : true,
				id : 'accountWin',
				region : 'center',
				title : '新增帐号',
				width : 500,
				height : 300,
				plain : true,
				items : [newaccountForm],
				buttons : [{
					text : '确定',
					id : 'save',
					handler : function() {
						var executeUrl = '';
						if (null == flow_orgid.getValue()
								|| flow_orgid.getValue() == undefined
								|| flow_orgid.getValue() == "") {
							Ext.Msg.alert("提示", '您尚未选择组织架构,无法提交');
							return;
						}

						if (newaccountForm.getForm().isValid()) {
							newaccountForm.getForm().submit({
								url : 'workflowAccountAction.action?actionType=1',
								waitMsg : '正在提交数据...',
								success : function(request, result) {/*
									resutjson = Ext
											.decode(result.response.responseText);
									accountstore.reload();
									accountWin.hide();
									newaccountForm.getForm().reset();
									Ext.Msg.show({
												title : '提示',
												msg : '保存成功',
												minWidth : 200,
												modal : true,
												icon : Ext.Msg.INFO,
												buttons : Ext.Msg.OK
											});
								*/},
								failure : function() {
									accountstore.reload();
									accountWin.hide();
									newaccountForm.getForm().reset();
									
									Ext.Msg.alert("提示", '保存成功');
								}
							})
						}
					}
				}, {
					text : '取消',
					id : 'cancel',
					handler : function() {
						accountWin.hide();
					}
				}]
			});
	// accountGrid.render(Ext.getBody());

	viewport = new Ext.Viewport({

				layout : 'border',
				items : [tree, accountGrid]
			});
});